package com.qf.factorybean;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author lwc
 * @date 2021/10/26 13:21
 * @Description
 *
 * FactoryBean 用来创建复杂的bean
 *
 * 里面是泛型
 */
public class MyFactoryBean  implements FactoryBean<Connection> {
    @Override
    public Connection getObject() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/javaee2110", "root", "123456");
        return connection;

    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    //默认方法可以被实现类覆盖
    @Override
    public boolean isSingleton() {
        return false;
    }
}
